const app = getApp() // 引入app
const _request = require("../../utils/request.js"); // 引入require;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    price: '',
    content: '',
    textLength: 0
  },

  handlePrice(e) {
    var text = e.detail.value;
    var reg = /^(\.*)(\d+)(\.?)(\d{0,2}).*$/g;
    if (reg.test(text)) { //正则匹配通过，提取有效文本
      text = text.replace(reg, '$2$3$4');
    } else {
      text = '';
    }
    return text;
  },

  handleContentInput(event) {
    this.setData({
      textLength: event.detail.value.length
    })
  },

  onSave:function(){
    let price = this.data.price;
    if(!price){
      wx.showToast({
        title: '服务价格不能为空',
        icon: 'none',
        duration: 2000
      })
      return;
    } else {
      const exp = /(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/;
      exp.test(price)
      console.log(exp.test(price))
      if (!exp.test(price)) {
        wx.showToast({
          title: '请输入正确的金额',
          icon: 'none',
          duration: 2000
        })
        return;
      }
    }
    _request.postObj('/stylistUser/getQrCode', {
      storeId: wx.getStorageSync('storeId'),
      tradePayAmount: this.data.price,
      remark: this.data.content
    }).then((res) => {
      if(res.data.code == 200){
        this.setData({
          price: '',
          content: ''
        })
        wx.navigateTo({
          url: "/pages/person/showcode/index?price=" + price + '&img=' + res.data.data
        });
      }
    })
    return;
    
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  }

})